<template>
  <div class="execution">
    <basic-container>
      <avue-crud ref="crud"
                 :page="page"
                 :data="tableFieldList"
                 :table-loading="tableLoading"
                 :option="fildListOption"
                 @on-load="getList"
                 @refresh-change="refreshChange"
                 @search-change="searchChange">
        <template slot-scope="scope"
                  slot="menu">
          <el-button type="text"
                     icon="el-icon-check"
                     size="mini"
                     plain
                     @click="handleDown(scope.row,scope.index)">显示属性
          </el-button>
        </template>
      </avue-crud>

      <el-dialog title="生成配置"
                 :visible.sync="box"
                 width="50%"
                 lock-scroll>
        <div class="pull-auto">
          <avue-form :option="formOption"
                     ref="formData"
                     v-model="formData"
                     @submit="gen()">
          </avue-form>
        </div>
      </el-dialog>
    </basic-container>
  </div>
</template>

<script>
  import { getTableInfp } from '@/views/system/gen/configTableApi'
  import {formOption, fildListOption} from '@/views/system/gen/configTableOption'
  import {mapGetters} from 'vuex'

  export default {
    name: 'code-generator',
    data() {
      return {
        tableSearch: {},
        tableName:'',
        tableFieldList: [],
        formData: {},
        box: false,
        page: {
          total: 0, // 总页数
          currentPage: 1, // 当前页数
          pageSize: 20 // 每页显示多少条
        },
        tableLoading: false,
        fildListOption: fildListOption,
        formOption: formOption
      }
    },
    created() {
      this.tableName = this.$route.query.tableName;
      console.info('业务表==>' + this.tableName);
    },
    mounted: function () {
    },
    computed: {
      ...mapGetters(['permissions'])
    },
    methods: {
      getList(page, params) {
        this.tableLoading = true
        let searchParam = this.tableSearch;
        let allParams = Object.assign(searchParam, {tableName : this.tableName});
        getTableInfp(allParams).then(response => {
          this.tableFieldList = response.data.data.tableFieldList
          this.page.total = response.data.total
          this.tableLoading = false
        })
      },
      handleDown: function (row, index) {
        this.formData.tableName = row.tableName
        this.box = true
      },
      /**
       * 刷新回调
       */
      refreshChange() {
        this.getList(this.page)
      },
      searchChange(form) {
        this.getList(this.page, form)
      },
      gen(form) {
        handleDown(this.formData).then(() => {
          this.box = true
        })
      }
    }
  }
</script>

<style lang="scss" scoped>
</style>

